package com.ytc.controller;

import com.ytc.dto.BookFeiLeiDto;
import com.ytc.model.Type;
import com.ytc.service.TypeService;
import com.ytc.util.RedisKeyCommon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 详细介绍类情况.
 *
 * @ClassName TypeController
 * @Author zk
 * @Date 2023/1/9
 * @Version 1.0
 */
@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;

    /**
     * 张阔：跳转分类页面
     * @return
     */
    @RequestMapping("toQuery")
//    @Cacheable(cacheNames = RedisKeyCommon.QUERY_BOOK_BY_DTO)
    public String toQuery(@RequestParam(required = false)String key, Model model){
        model.addAttribute("key",key);
        return "type/showClassification";
    }
    /**
     * 张阔： 查询频道
     * @return
     */
    @RequestMapping("queryBigTypeList")
    @ResponseBody
    @Cacheable(RedisKeyCommon.QUERY_BIG_TYPE)
    public List<Type> queryBigTypeList(){
       return typeService.queryBigTypeList();
    }

    /**
     * 张阔： 查询作品
     * @param pid
     * @return
     */
    @RequestMapping("querySmallTypeList")
    @ResponseBody
    @Cacheable(cacheNames = RedisKeyCommon.QUERY_SMALL_TYPE,key = "#pid")
    public List<Type> querySmallTypeList(Integer pid){
        return typeService.querySmallTypeList(pid);
    }


}
